<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/jsp/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Dotnet2-web 后台管理系统</title>
<!--[if lt IE 9]>
<script src="js/html5.js"></script>
<![endif]-->
<%@ include file="/jsp/common/commonJs.jsp"%>
</head>
<body>
<!--header-->
<%@ include file="/jsp/top.jsp"%>
<!--header-->

<!--aside nav-->
<%@ include file="/jsp/left.jsp"%>
<!--aside nav  -->

<section class="rt_wrap content mCustomScrollbar">
 <div class="rt_content">
     <!--点击加载-->
     <script>
     $(document).ready(function(){
		$("#loading").click(function(){
			$(".loading_area").fadeIn();
             $(".loading_area").fadeOut(1500);
			});
		 });
     </script>
     <section class="loading_area">
      <div class="loading_cont">
       <div class="loading_icon"><i></i><i></i><i></i><i></i><i></i></div>
       <div class="loading_txt"><mark>数据正在加载，请稍后！</mark></div>
      </div>
     </section>
     <!--结束加载-->
     <!--弹出框效果-->
     <script>
     $(document).ready(function(){
		 //弹出文本性提示框
		 $("#showPopTxt").click(function(){
			 $(".pop_bg").fadeIn();
			 });
		 //弹出：确认按钮
		 $(".trueBtn").click(function(){
			 alert("你点击了确认！");//测试
			 $(".pop_bg").fadeOut();
			 });
		 //弹出：取消或关闭按钮
		 $(".falseBtn").click(function(){
			 alert("你点击了取消/关闭！");//测试
			 $(".pop_bg").fadeOut();
			 });
		 });
     </script>

     <section>
      <input type="button" value="按钮input" class="link_btn"/>
     </section>
     
     <!-- 可编辑 -->
     <c:if test="${order.orderStatus==0 || order.orderStatus==1}">
		 	  <section>
		 	  <form id="orderInfo" method="post">
		      <h2><strong style="color:grey;">客户信息</strong></h2>
		      <ul class="ulColumn2">
		      	<input type="hidden" name="id" value="${order.id}" />
		        <li>名称：<input type="text" class="textbox textbox_225" name="userName" value="${order.userName}" placeholder="class=225px..."/> </li>
		        <li>单位：<input type="text" class="textbox textbox_225" name="userUnit" value="${order.userUnit}" placeholder="class=225px..."/></li>
		      	<li>地址：<input type="text" class="textbox textbox_225" name="userAddress" value="${order.userAddress}" placeholder="class=225px..."/></li>
		      	<li>电话：<input type="text" class="textbox textbox_225" name="userPhone" value="${order.userPhone}" placeholder="class=225px..."/></li>
		      	<li><input type="button" value="修改客户信息" onclick="updateUserInfo('orderInfo')"  /></li>
		      </ul>
		      </form>
		      </section>
		      <c:forEach items="${opc}" var="opc">
		      	<form id="form${opc.id}">
		      	 <section>
			      	<h2><strong style="color:grey;">${opc.productName}</strong>
			      	<span style="float: right; margin-right: 50%;">${opc.productName}产品当前状态：(<span id="ps">${opc.productStatus==0?"<font color=orange>待审核</font>":opc.productStatus==1?"<font color=green>审核通过</font>":"<font color=red>审核未通过</font>"}</span>)</span></h2>
				      <ul class="ulColumn2">
				      	<input type="hidden" name="id" id="id" value="${opc.id}">
				      	<%-- <li>期限：<input type="text" class="textbox textbox_225" name="productTime" value="${opc.productTime}" placeholder="class=225px..."/></li> --%>
				      	<c:if test="${fn:length(opc.orderFieldList) > 0 }">
				      		<c:forEach items="${opc.orderFieldList}" var="of">
				      			<c:if test="${of.fieldType!='radio' && of.fieldType!='select' && of.fieldType!='textdate' && of.fieldType!='checkbox'}">
				      				<li>${of.fieldName}：<input type="text" class="textbox textbox_225" name="${of.inputName}" value="${of.fieldValue}"></li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='textdate'}">
				      				<li>${of.fieldName}：<input type="text" onClick="WdatePicker({dateFmt:'yyyy年MM月dd日',minDate:'%y-%M-%d}'})"   class="Wdate" name="${of.inputName}" value="${of.fieldValue}"></li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='radio'}">
				      				<li>
				      					${of.fieldName}：
				      					<c:forEach items="${of.fieldTypeValue}" var="list">
				      						<c:forEach items="${of.fieldTypeValuePrice}" var="valuelist">
				      							<c:if test="${list.id==valuelist.id}">
				      								<input type="radio" name="${of.inputName}" value="${valuelist.value}" <c:if test="${of.fieldValue==valuelist.value}">checked</c:if>>${list.value}
				      							</c:if>
				      						</c:forEach>
				      					</c:forEach>
				      				</li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='checkbox'}">
				      				<li>
				      					${of.fieldName}：
				      					<c:set var="fvValue" value="${of.fieldValue}" />
				      					<c:forEach items="${of.fieldTypeValue}" var="list">
				      						<c:forEach items="${of.fieldTypeValuePrice}" var="valuelist">
				      							<c:if test="${list.id==valuelist.id}">
				      								<%-- ${fn:replace(valuelist.value, '.0', '')} --%>
				      								<%-- ${fn:contains(fvValue, value)} --%>
				      								<input type="checkbox" name="${of.inputName}" value="${valuelist.value}" <c:if test="${fn:contains(fvValue, fn:replace(valuelist.value, '.0', ''))}">checked</c:if>>${list.value}
				      							</c:if>
				      						</c:forEach>
				      					</c:forEach>
				      				</li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='select'}">
				      				<li>
	      					${of.fieldName}：<select name="${of.inputName}">
	      										<c:forEach items="${of.fieldTypeValue}" var="list">
						      						<c:forEach items="${of.fieldTypeValuePrice}" var="valuelist">
						      							<c:if test="${list.id==valuelist.id}">
						      								<option value="${valuelist.value}" <c:if test="${of.fieldValue==valuelist.value}">selected</c:if> >${list.value}</option>
						      							</c:if>
						      						</c:forEach>
						      					</c:forEach>
			      						</select>
				      				</li>
				      			</c:if>
				      		</c:forEach>
				      		<li>产品价格：<input type="text" class="textbox textbox_225" name="productPrice" value="${opc.productPrice}" placeholder="class=225px..."/></li>
				      		<li>折扣价:<input type="text" class="textbox textbox_225" onblur="setPrice('form${opc.id}')" name="zkprice" placeholder="class=225px..." /> </li>
				      	</c:if>
				      </ul>
			      </section>
			      <input type="button" value="审核通过" onclick="sub('form${opc.id}','1')"  />
			      <input type="button" value="审核不通过" onclick="sub('form${opc.id}','2')"  />
		 	   </form>
		      </c:forEach>
		      <h2>总价:<span id="total"></span></h2>
		      <h2><input type="button" value="审核完成" onclick="passOrder('${order.id}','${order.orderNo}')">
		      	  <a href="javascript:bye()">离开此页</a>
		      </h2>
		 </div>
		</section>
     </c:if>
     <!-- 不可编辑 -->
      <c:if test="${order.orderStatus!=0 && order.orderStatus!=1}">
      	<c:set var="count" value="0"/>
		 <section>
		      <h2><strong style="color:grey;">客户信息</strong></h2>
		      <ul class="ulColumn2">
		        <li>名称：${order.userName}</li>
		        <li>单位：${order.userUnit}</li>
		      	<li>地址：${order.userAddress}</li>
		      	<li>电话：${order.userPhone}</li>
		      </ul>
		      </section>
		      <c:forEach items="${opc}" var="opc">
		      	<form id="form${opc.id}">
		      	 <section>
			      	<h2><strong style="color:grey;">${opc.productName}</strong>
			      	<span style="float: right; margin-right: 50%;">${opc.productName}产品当前状态：(${opc.productStatus==0?"<font color=orange>待审核</font>":opc.productStatus==1?"<font color=green>审核通过</font>":"<font color=red>审核未通过</font>"})</span></h2>
				      <ul class="ulColumn2">
				      	<%-- <li>期限：${opc.productTime}</li> --%>
				      	<%-- <li>折扣价:<input type="text" name="zkprice" onblur="setPrice('form${opc.id}')"></li> --%>
				      	<c:if test="${fn:length(opc.orderFieldList) > 0 }">
				      		<c:forEach items="${opc.orderFieldList}" var="of">
				      			<c:if test="${of.fieldType!='radio' && of.fieldType!='select'}">
				      				<li>${of.fieldName}：${of.fieldValue}</li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='radio'}">
				      				<li>
				      					${of.fieldName}：
				      					<c:forEach items="${of.fieldTypeValue}" var="list">
				      						<c:forEach items="${of.fieldTypeValuePrice}" var="valuelist">
				      							<c:if test="${list.id==valuelist.id}">
				      								<input type="radio" name="${of.inputName}" disabled value="${valuelist.value}" <c:if test="${of.fieldValue==valuelist.value}">checked</c:if>>${list.value}
				      							</c:if>
				      						</c:forEach>
				      					</c:forEach>
				      				</li>
				      			</c:if>
				      			<c:if test="${of.fieldType=='select'}">
				      				<li>
	      					${of.fieldName}：<select disabled name="${of.inputName}">
	      										<c:forEach items="${of.fieldTypeValue}" var="list">
						      						<c:forEach items="${of.fieldTypeValuePrice}" var="valuelist">
						      							<c:if test="${list.id==valuelist.id}">
						      								<option value="${valuelist.value}" <c:if test="${of.fieldValue==valuelist.value}">selected</c:if> >${list.value}</option>
						      							</c:if>
						      						</c:forEach>
						      					</c:forEach>
			      						</select>
				      				</li>
				      			</c:if>
				      		</c:forEach>
				      		<li>产品价格：${opc.productPrice}</li>
				      	</c:if>
				      </ul>
			      </section>
			      <%-- <input type="button" value="审核通过" onclick="sub('form${opc.id}','1')"  />
			      <input type="button" value="审核不通过" onclick="sub('form${opc.id}','2')"  /> --%>
		 	   </form>
		 	   <c:set var="count" value="${count+opc.productPrice}"/>
		      </c:forEach>
		      <h2>总价:<span id="total">${count}￥</span></h2>
		      <h2>
		      	 <%--  <input type="button" value="审核完成" onclick="passOrder('${order.id}','${order.orderNo}')"> --%>
		      	  <a href="javascript:bye()">离开此页</a>
		      </h2>
		 </div>
		</section>
     </c:if>
</body>
<script>
$(function(){
	//清空折扣价
	
	$("input[name=zkprice]").each(function(){
		$(this).val(0);
	});
	//不可编辑时 总价
	var count='${count}';
	if(''==count){
		var total=setTotalPrice();
		$("#total").text(total);
	}
	$("form").each(function(){
		setPrice($(this).attr("id"));
	})
	
});

//设置价格
function setPrice(formId){
	var flag=true;
	var obj=$("#"+formId+"");
	//原价
	var price = obj.find("input[name=productPrice]").val();
	//折扣价
	var zkprice= obj.find("input[name=zkprice]").val();
	if(''==zkprice){
		alert("请先输入折扣价");
		flag=false;
		return;
	}else{
		if(parseInt(zkprice)>parseInt(price)){
			alert("折扣价不能大于原价!");
			flag=false;
			return;
		}
		if(!comparePrice()){
			alert("存在折扣价大于原价的产品!");
			flag=false;
			return;
		}
		var total=setTotalPrice();
		var zktotal=0;
		var result=0;
		//total=parseInt(total)-parseInt(zkprice);
		$("input[name=zkprice]").each(function(){
			if(''!=$(this).val()){
				zktotal=parseInt(zktotal)+parseInt($(this).val());
			}
		});
		result=parseInt(total)-parseInt(zktotal);
		$("#total").text(total+"-"+zktotal+"="+result);
	}
	return flag;
}

//查询表单中是否存在 折扣价大于原价的情况

function comparePrice(){
	var flag=true;
	$("form").each(function(){
		var price=$(this).find("input[name=productPrice]").val();
		var zkprice=$(this).find("input[name=zkprice]").val();
		if(''!=zkprice){
			//alert("原价:"+price+"折扣价:"+zkprice);
			if(parseInt(zkprice)>parseInt(price)){
				flag=false;
			}
		}
	});
	return flag;
}

//设置总价
function setTotalPrice(){
	var total=0;
	$("input[name=productPrice]").each(function(){
		total=parseInt(total)+parseInt($(this).val());
	});
	return total;
	//$("#total").text(total);
}

//审核产品
function sub(formId,productStatus){
	var flag=setPrice(formId);
	if(flag){
		//原价
		var price=$("#"+formId+"").find("input[name=productPrice]").val();
		//折扣价
		var zkprice=$("#"+formId+"").find("input[name=zkprice]").val();
		//原价-折扣价
		$("#"+formId+"").find("input[name=productPrice]").val(parseInt(price)-parseInt(zkprice));
		//提交表单
		js.updateProduct(formId,"审核成功","审核失败",productStatus,"ps");
		$("#"+formId+"").find("input[name=zkprice]").val(0);
	}
}
//审核订单
function passOrder(orderId,orderNo){
	$.ajax({
        type: "post",
        url: "${path}/order/updateOrder.do",
        data: {id:orderId,orderNo:orderNo},
        dataType: "json",
        success: function(data){
        	if(data.status){
        		alert(data.msg);
        		window.location.href="${path}/order/orderList.do";
        	}else{
        		alert(data.msg);
        	}
        }
    });
}
//离开当前页
function bye(){
	js.byeThePage('/order/orderList.do');
}
//修改客户信息
function updateUserInfo(formId){
	var options = {
			url : js.path()+"/order/updateUserInfo.do",
			type : "post",
			dataType : "json",
			success : function(data){
				if(data.status){
					alert("修改客户信息成功!");
				}else{
					alert("修改客户信息失败!");
				}
			}
	};
	$("#"+formId+"").ajaxSubmit(options);
}
</script>
</html>